﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.SM
{
    public partial class LoadHousingDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                setUrl();
            }
        }

        // 设置 首条 上一条 下一条 尾条 
        private void setUrl()
        {
            string id = _Request.GetString("id");               // 当前ID
            string id_list = _Request.GetString("id_list");     // 所有ID字符串            

            if (id_list.IndexOf(",") < 0)
            {
                btnFirst.Visible = false;
                btnPrev.Visible = false;
                btnNext.Visible = false;
                btnLast.Visible = false;

                return;
            }

            string[] m_sIdiList = id_list.Split(',');   // 所有ID数组
            int m_nPos = 0;

            //检查位置
            int listLength = m_sIdiList.Length;
            for (int i = 0; i < listLength; i++)
            {
                if (m_sIdiList[i] == id)
                {
                    m_nPos = i;
                    break;
                }
            }

            this.btnFirst.Attributes["onclick"] = "javascript:window.location.href='LoadHousingDetail.aspx?id=" + m_sIdiList[0] + "&id_list=" + id_list + "';return false;";
            if (m_nPos != 0)
            {
                this.btnPrev.Enabled = true;
                this.btnFirst.Enabled = true;
                this.btnPrev.Attributes["onclick"] = "javascript:window.location.href='LoadHousingDetail.aspx?id=" + m_sIdiList[m_nPos - 1] + "&id_list=" + id_list + "';return false;";
            }
            else
            {
                this.btnPrev.Enabled = false;
                this.btnFirst.Enabled = false;
            }
            if (m_nPos != m_sIdiList.Length - 1)
            {
                this.btnNext.Enabled = true;
                this.btnLast.Enabled = true;
                this.btnNext.Attributes["onclick"] = "javascript:window.location.href='LoadHousingDetail.aspx?id=" + m_sIdiList[m_nPos + 1] + "&id_list=" + id_list + "';return false;";
            }
            else
            {
                this.btnNext.Enabled = false;
                this.btnLast.Enabled = false;
            }
            this.btnLast.Attributes["onclick"] = "javascript:window.location.href='LoadHousingDetail.aspx?id=" + m_sIdiList[m_sIdiList.Length - 1] + "&id_list=" + id_list + "';return false;";
        }
    }
}
